﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model;
using HengTong.Model.Db.Hr.Bill;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel.Hr.SysHrStaffNeedRequestBillEntryVms
{
    public partial class SysHrStaffNeedRequestBillEntryListVm : BasePagedListVM<SysHrStaffNeedRequestBillEntryView,
        SysHrStaffNeedRequestBillEntrySearcher>
    {
        protected override IEnumerable<IGridColumn<SysHrStaffNeedRequestBillEntryView>> InitGridHeader()
        {
            return new List<GridColumn<SysHrStaffNeedRequestBillEntryView>>
            {
                this.MakeGridHeader(x => x.HireNumber),
                this.MakeGridHeader(x => x.ApplyReason),
                this.MakeGridHeader(x => x.ExpectedDate),
                this.MakeGridHeader(x => x.JobRequirement),
                this.MakeGridHeader(x => x.EducationRequirement),
                this.MakeGridHeader(x => x.MajorRequirement),
                this.MakeGridHeader(x => x.GenderRequirement),
                this.MakeGridHeader(x => x.AgeRequirement),
                this.MakeGridHeader(x => x.OtherRequirement),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.OrgName),
                this.MakeGridHeader(x => x.JobPositionName),
                this.MakeGridHeader(x => x.HrStaffNeedName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysHrStaffNeedRequestBillEntryView> GetSearchQuery()
        {
            var query = DC.Set<SysHrStaffNeedRequestBillEntry>()
                .CheckBetween(Searcher.ExpectedDate?.GetStartTime(), Searcher.ExpectedDate?.GetEndTime(),
                    x => x.ExpectedDate, includeMax: false)
                .CheckContain(Searcher.JobRequirement, x => x.JobRequirement)
                .CheckEqual(Searcher.EducationRequirement, x => x.EducationRequirement)
                .CheckContain(Searcher.MajorRequirement, x => x.MajorRequirement)
                .CheckEqual(Searcher.GenderRequirement, x => x.GenderRequirement)
                .CheckContain(Searcher.AgeRequirement, x => x.AgeRequirement)
                .CheckEqual(Searcher.GroupId, x => x.GroupId)
                .CheckEqual(Searcher.OrgId, x => x.OrgId)
                .CheckEqual(Searcher.JobPositionId, x => x.JobPositionId)
                .CheckEqual(Searcher.HrStaffNeedId, x => x.HrStaffNeedId)
                .Select(x => new SysHrStaffNeedRequestBillEntryView
                {
                    ID = x.ID,
                    HireNumber = x.HireNumber,
                    ApplyReason = x.ApplyReason,
                    ExpectedDate = x.ExpectedDate,
                    JobRequirement = x.JobRequirement,
                    EducationRequirement = x.EducationRequirement,
                    MajorRequirement = x.MajorRequirement,
                    GenderRequirement = x.GenderRequirement,
                    AgeRequirement = x.AgeRequirement,
                    OtherRequirement = x.OtherRequirement,
                    GroupName = x.Group.GroupName,
                    OrgName = x.HrStaffNeed.Org.Name,
                    JobPositionName = x.JobPosition.Name,
                    HrStaffNeedName = x.HrStaffNeed.BillCode,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysHrStaffNeedRequestBillEntryView : SysHrStaffNeedRequestBillEntry
    {
        [Display(Name = "_Admin.GroupName")] public String GroupName { get; set; }
        [Display(Name = "岗位名称")] public String JobPositionName { get; set; }
        [Display(Name = "单据编号")] public String HrStaffNeedName { get; set; }

        [Display(Name = "公司名称")] public String OrgName { get; set; }
    }
}